clear
clear matrix
clear mata
set more off, perm
set matsize 11000
set maxvar 30000
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/
global output /Users/zachbrown/Projects/PriceTransparency/Output

// open visit dataset
use clean/radiology_visit_3.dta, clear

// Make treatment indicator
gen post = (ym>=ym(2007,3))
gen web_post = (visit_on_web==1 & post==1)
label var web_post "$\text{OnWeb}\textsubscript{m}\times\text{Post}\textsubscript{t}$"

// Set X controls 
global ctrvars1 = "has_copay has_coin##deduct_type age male zip_mean_income zip_pct_ba "
global ctrvars2 = "age male zip_mean_income zip_pct_ba"


///////////////////////
// Baseline Allowed Amt
///////////////////////

reghdfe ln_amt_allowed web_post $ctrvars1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a1

reghdfe ln_amt_allowed web_post $ctrvars2 if has_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a2

reghdfe ln_amt_allowed web_post $ctrvars2 if past_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a3

reghdfe ln_amt_allowed web_post $ctrvars2 if past_deduct==1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_allowed if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo a4

esttab a1 a2 a3 a4 using $output/base_regs_a1.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab a1 a2 a3 a4 using $output/base_regs_a2.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp r2_a N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 



///////////////////////
// Baseline OOP
///////////////////////

reghdfe ln_amt_member_oop web_post $ctrvars1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo b1

reghdfe ln_amt_member_oop web_post $ctrvars2 if has_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo b2

reghdfe ln_amt_member_oop web_post $ctrvars2 if past_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo b3

reghdfe ln_amt_member_oop web_post $ctrvars2 if past_deduct==1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_member_oop if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo b4

esttab b1 b2 b3 b4 using $output/base_regs_b1.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab b1 b2 b3 b4 using $output/base_regs_b2.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp r2_a N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 



///////////////////////
// Baseline Paid
///////////////////////

reghdfe ln_amt_paid web_post $ctrvars1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo c1

reghdfe ln_amt_paid web_post $ctrvars2 if has_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo c2

reghdfe ln_amt_paid web_post $ctrvars2 if past_deduct==0, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo c3

reghdfe ln_amt_paid web_post $ctrvars2 if past_deduct==1, absorb(proc_id_radio ym std_product_type payer_id rural_class charlindex) vce(cl ym) 
summ amt_paid if e(sample), meanonly
estadd scalar ymeanexp = r(mean), replace
eststo c4

esttab c1 c2 c3 c4 using $output/base_regs_c1.tex, frag cells(b(fmt(3) star) se(fmt(3) par)) ///
	keep(web_post)  stats() ///
	starlevels(`"\sym{*}"' 0.1 `"\sym{**}"' 0.05 `"\sym{***}"' 0.01, label(" \(p<@\)")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) ///
 	noobs collabels(none) booktabs gaps nonumber label  nonote replace nomtitles nodepvars 
	
esttab c1 c2 c3 c4 using $output/base_regs_c2.tex, frag	cells(b(fmt(3) star)) ///
	drop(*)  stats(ymeanexp r2_a N, fmt(2 3 %12.0fc) labels("Mean level" "Adjusted R2" "Observations") layout("\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}" "\multicolumn{1}{c}{@}")) ///
	varwidth(20) modelwidth(12) delimiter(&) end(\\) collabels(none) nolines ///
	nonumber label  nonote replace nomtitles nodepvars noisily 




	

	
